package com.dormitory.dormitorymanagement.controller;


import com.dormitory.dormitorymanagement.pojo.*;
import com.dormitory.dormitorymanagement.pojo.dto.CommentsDto;
import com.dormitory.dormitorymanagement.pojo.dto.EvaluationDto;
import com.dormitory.dormitorymanagement.pojo.dto.PostsDto;
import com.dormitory.dormitorymanagement.pojo.dto.ReplyDto;
import com.dormitory.dormitorymanagement.pojo.vo.PostsVo;
import com.dormitory.dormitorymanagement.pojo.vo.StudentEvaluationsVo;
import com.dormitory.dormitorymanagement.service.StudentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
@CrossOrigin(origins = "http://localhost:8081", allowedHeaders = "*")
public class StudentController {


    @Autowired
    StudentsService studentsService;
    @PostMapping("/repair")
    public Result repair(@RequestBody DormRepair dormRepair)
    {
        studentsService.insert(dormRepair);
        return Result.success();
    }

    @GetMapping("/notice/latest")
    public Result<List<Notice>>  getLatestNotice(@RequestParam String studentId,@RequestParam Integer pageSize){

        return Result.success(studentsService.getLatestNotice(studentId,pageSize));
    }

    @GetMapping("/notice/detail")
    public Result<Notice> getNoticeDetail(@RequestParam Integer id){
        Notice notice = studentsService.getNoticeDetail(id);
        return Result.success(notice);
    }


    @GetMapping("/classnotice/latest")
    public Result<List<ClassNotice>>  getLatestClassNotice(@RequestParam String studentId, @RequestParam Integer pageSize){

        return Result.success(studentsService.getLatestClassNotice(studentId,pageSize));
    }


    @GetMapping("/classnotice/detail")
    public Result<ClassNotice> getClassNoticeDetail(@RequestParam Integer id){
        ClassNotice notice = studentsService.getClassNoticeDetail(id);
        return Result.success(notice);
    }


    @GetMapping("/courses")
    public Result getCources(@RequestParam String studentId){
        List<CourseSchedule> courses = studentsService.getCources(studentId);
        return Result.success(courses);
    }


    @GetMapping("/leader")
    public Result<PageBean<Students>>  getClassLeader(@RequestParam String studentId,@RequestParam Integer page, @RequestParam Integer pageSize){

        return Result.success(studentsService.getClassLeader(studentId,page,pageSize));
    }


    @GetMapping("/dorm")
    public Result<PageBean<DormitoryAdmin>>  getDormAdmin(@RequestParam String studentId,@RequestParam Integer page, @RequestParam Integer pageSize){

        return Result.success(studentsService.getDormAdmin(studentId,page,pageSize));
    }

    @PostMapping("/submit")
    public Result submit(@RequestBody EvaluationDto evaluationDto) {
        studentsService.submit(evaluationDto);
        return Result.success();
    }



    @GetMapping("/evaluation")
    public Result<StudentEvaluations>  getStudentEvaluations(@RequestParam String targetId,@RequestParam String  targetType){

        return Result.success(studentsService.getStudentEvaluations(targetId,targetType));
    }



    @PostMapping("/post")
    public Result posts(@RequestBody PostsDto postsDto) {
        studentsService.postsSubmit(postsDto);
        return Result.success();
    }


    @GetMapping("/posts")
    public Result<List<PostsVo>>  getPostsList(@RequestParam String studentId){

        return Result.success(studentsService.getPostsList(studentId));
    }



    @PostMapping("/reply")
    public Result reply(@RequestBody ReplyDto replyDto) {
        studentsService.replySubmit(replyDto);
        return Result.success();
    }



    @PostMapping("/comment")
    public Result comment(@RequestBody CommentsDto commentDto) {
        studentsService.commentSubmit(commentDto);
        return Result.success();
    }

    @GetMapping("/myevaluation")
    public Result<PageBean<StudentEvaluationsVo>>  getStudentMyEvaluations(@RequestParam String studentId, @RequestParam Integer page, @RequestParam Integer pageSize){

        return Result.success(studentsService.getStudentMyEvaluations(studentId,page,pageSize));
    }










//    @GetMapping("/list")
//    public Result getStudentsByPost(@RequestParam("studentIds")List<String> studentIds) {
//        List<Students> students = studentsService.getStudentsByIds(studentIds);
//        return Result.success(students);
//    }



//    @GetMapping("/list")
//    public Result getStudentsByPost(@RequestParam("studentIds")List<String> studentIds) {
//        List<Students> students = studentsService.getStudentsAll();
//        return Result.success(students);
//    }
}
